﻿using System;
using System.Collections.Generic;
using UnityEngine;

// Token: 0x020001F2 RID: 498
public class BehaviorLists
{
	// Token: 0x06000AA2 RID: 2722 RVA: 0x0005B309 File Offset: 0x00059509
	public static void Initialize()
	{
		BehaviorLists.Instance = new BehaviorLists();
	}

	// Token: 0x06000AA3 RID: 2723 RVA: 0x0005B315 File Offset: 0x00059515
	public void AddBehavior(IBehavior behavior)
	{
		if (this.behaviorList == null)
		{
			this.behaviorList = new List<IBehavior>();
		}
		this.behaviorList.Add(behavior);
	}

	// Token: 0x06000AA4 RID: 2724 RVA: 0x0005B339 File Offset: 0x00059539
	public void AddMotive(IMotive motive)
	{
		if (this.motiveList == null)
		{
			this.motiveList = new List<IMotive>();
		}
		Debug.Log("Found: " + motive.GetName());
		this.motiveList.Add(motive);
	}

	// Token: 0x06000AA5 RID: 2725 RVA: 0x0005B372 File Offset: 0x00059572
	public List<IMotive> GetMotives()
	{
		return this.motiveList;
	}

	// Token: 0x06000AA6 RID: 2726 RVA: 0x0005B37C File Offset: 0x0005957C
	public IBehavior GetBehavior(string behaviorName)
	{
		for (int i = 0; i < this.behaviorList.Count; i++)
		{
			if (this.behaviorList[i].GetName() == behaviorName)
			{
				return this.behaviorList[i];
			}
		}
		Debug.LogError("Behavior " + behaviorName + " not found");
		return null;
	}

	// Token: 0x06000AA7 RID: 2727 RVA: 0x0005B3E4 File Offset: 0x000595E4
	public List<IBehavior> FindBehaviors(EntityBase agent, EntityBase target)
	{
		return this.FindBehaviors(this.FindDefs(agent, null), this.FindDefs(target, agent));
	}

	// Token: 0x06000AA8 RID: 2728 RVA: 0x0005B3FC File Offset: 0x000595FC
	public List<IBehavior> FindBehaviors(List<TargetType> agentDefs, List<TargetType> targetDefs)
	{
		List<IBehavior> list = new List<IBehavior>();
		for (int i = 0; i < this.behaviorList.Count; i++)
		{
			IBehavior behavior = this.behaviorList[i];
			if (behavior.IsEnabled())
			{
				if (this.EntityMatch(agentDefs, behavior.GetAgentDef()) && !this.IsExcluded(agentDefs, behavior.GetAgentDef()) && this.EntityMatch(targetDefs, behavior.GetTargetDef()) && !this.IsExcluded(targetDefs, behavior.GetTargetDef()))
				{
					list.Add(behavior);
				}
			}
		}
		return list;
	}

	// Token: 0x06000AA9 RID: 2729 RVA: 0x0005B498 File Offset: 0x00059698
	public List<IBehavior> GetAllBehaviors()
	{
		List<IBehavior> list = new List<IBehavior>();
		list.AddRange(this.behaviorList);
		return list;
	}

	// Token: 0x06000AAA RID: 2730 RVA: 0x0005B4B8 File Offset: 0x000596B8
	public List<TargetType> FindDefs(EntityBase a, EntityBase b = null)
	{
		List<TargetType> list = new List<TargetType>();
		if (a == null)
		{
			list.Add(TargetType.None);
			return list;
		}
		if (a == b)
		{
			list.Add(TargetType.Oneself);
		}
		if (a.isHumanoid)
		{
			list.Add(TargetType.Humanoid);
		}
		if (a.isPlayer)
		{
			list.Add(TargetType.Player);
		}
		if (a.isMicro)
		{
			list.Add(TargetType.Micro);
		}
		if (a.isGiantess)
		{
			list.Add(TargetType.Giantess);
		}
		return list;
	}

	// Token: 0x06000AAB RID: 2731 RVA: 0x0005B53C File Offset: 0x0005973C
	private bool EntityMatch(List<TargetType> defs, EntityDef entityDef)
	{
		if (entityDef.include.Contains(TargetType.None))
		{
			return true;
		}
		for (int i = 0; i < defs.Count; i++)
		{
			for (int j = 0; j < entityDef.include.Count; j++)
			{
				TargetType targetType = entityDef.include[j];
				if (defs[i] == targetType)
				{
					return true;
				}
			}
		}
		return false;
	}

	// Token: 0x06000AAC RID: 2732 RVA: 0x0005B5B0 File Offset: 0x000597B0
	private bool IsExcluded(List<TargetType> defs, EntityDef entityDef)
	{
		for (int i = 0; i < defs.Count; i++)
		{
			for (int j = 0; j < entityDef.exclude.Count; j++)
			{
				TargetType targetType = entityDef.exclude[j];
				if (defs[i] == targetType)
				{
					return true;
				}
			}
		}
		return false;
	}

	// Token: 0x04000FC4 RID: 4036
	public static BehaviorLists Instance;

	// Token: 0x04000FC5 RID: 4037
	private List<IBehavior> behaviorList;

	// Token: 0x04000FC6 RID: 4038
	private List<IMotive> motiveList;
}
